package com.benmei.ntlive.exception;

import org.springframework.http.HttpStatus;

/**
 * Created by Peter on 2017/8/1.
 * 服务器端异常
 */
public class NtServerException extends Throwable {
    //错误产生时的时间戳
    private long timestamp = System.currentTimeMillis();

    //状态码，类型：int
    private int status = HttpStatus.INTERNAL_SERVER_ERROR.value();

    //错误信息，给最终用户的提示信息，类型：String
    private String error = HttpStatus.INTERNAL_SERVER_ERROR.name();

    //错误详细信息，给最终用户的更多的提示信息，类型：String
    private String message = "No message available";

    private String action;

    public NtServerException(String message) {
        this.message = message;
    }

    public NtServerException(String message, String action) {
        this.message = message;
        this.action = action;
    }

    public String getAction() {
        return action;
    }

    public void setAction(String action) {
        this.action = action;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getError() {
        return error;
    }

    public void setError(String error) {
        this.error = error;
    }

    @Override
    public String toString() {
        return "{\"timestamp\":" + timestamp +
                ",\"status\":" + status +
                ", \"error\":\"" + error + "\"" +
                ", \"action\":\"" + action + "\"" +
                ", \"message\":\"" + message + "\"" + "}";
    }

    public String toJson() {
        return "{\"timestamp\":" + timestamp +
                ",\"status\":" + status +
                ", \"error\":\"" + error + "\"" +
                ", \"action\":\"" + action + "\"" +
                ", \"message\":\"" + message + "\"" + "}";
    }
}
